﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using CRM.Entity;

using CRM.BLL;
using DP.Web.UI.Controls;
using DP.Web.UI;
using DP.Common;

namespace CRM.Web.RepairCaseManage
{
    public partial class ToDoList : Common.PageBase
    {

        public string ModifyUrl = "Modify.aspx?CASEID={0}";

        #region 业务访问对象

        /// <summary>
        /// 报修工单业务访问对象
        /// </summary>
        private T_REPAIRCASE_BLL bll = new T_REPAIRCASE_BLL();

        /// <summary>
        /// 人员内容权限业务访问对象
        /// </summary>
        private T_CONTENTAUTHORITY_BLL caBll = new T_CONTENTAUTHORITY_BLL();

        /// <summary>
        /// 角色状态业务访问对象
        /// </summary>
        private T_ROLEORDERSTATUSAUTHORITY_BLL roleOrderStatusAuthorityBll = new T_ROLEORDERSTATUSAUTHORITY_BLL();

        /// <summary>
        /// 工单状态业务访问对象
        /// </summary>
        private T_WORKORDERSTATUS_BLL workOrderStatusBll = new T_WORKORDERSTATUS_BLL();

        /// <summary>
        /// 数据字典业务访问对象
        /// </summary>
        private T_DICTIONARY_BLL dBll = new T_DICTIONARY_BLL();

        #endregion

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            gvList.PageSize = StringHelper.ToInt(configBll.GetCacheValueByName(this.Page, "PageSize"), 20);
            PageHelper.SetPrePageUrl(this.Page);
            PageHelper.SetPopCalender(this.Page, txtCREATETIMEBegin);
            PageHelper.SetPopCalender(this.Page, txtCREATETIMEEnd);

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlSMSSTATUSBinding();
                ddlSTATUSBinding();
                GetUrlQueryToControl();
                gvDataBinding();
            }
        }

        #region 页面初始化数据绑定

        /// <summary>
        /// 短信回复状态
        /// DDLs the SMSSTATUS binding.
        /// </summary>
        private void ddlSMSSTATUSBinding()
        {
            EnumHelper.FillListControl(ddlSMSSTATUS, typeof(RepairReplyStatus));
            ddlSMSSTATUS.Items.Insert(0, new ListItem("", ""));
        }

        /// <summary>
        /// DDLs the STATUS binding.
        /// </summary>
        private void ddlSTATUSBinding()
        {

            ddlSTATUS.DataSource =
                roleOrderStatusAuthorityBll.GetList(string.Format(" and RoleID = '{0}' and OrderTypeID = '{1}' ",
                                                                  _userLoginInfo.UserEntity.ROLEID.ToString(),
                                                                  ((int)WorkOrderType.报修工单).ToString()));

            ddlSTATUS.DataTextField = "ORDERSTATUSNAME";
            ddlSTATUS.DataValueField = "ORDERSTATUSID";
            ddlSTATUS.DataBind();
            ddlSTATUS.Items.Insert(0, new ListItem("", ""));
        }

        #endregion

        /// <summary>
        /// 获取 URL 上的参数存入当页面 控件中。
        /// </summary>
        private void GetUrlQueryToControl()
        {
            PageHelper.GetUrlQueryToControl(this.Page);
        }

        /// <summary>
        /// 生成查询条件字符串
        /// </summary>
        private StringBuilder GenerationSQLString()
        {
            StringBuilder sql = new StringBuilder();
            #region 链接地址部分
            if (!String.IsNullOrEmpty(Request.QueryString["CASEID"]))
            {
                sql.Append(" and CASEID like '%" + Request.QueryString["CASEID"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLER"]))
            {
                sql.Append(" and CALLER like '%" + Request.QueryString["CALLER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLED"]))
            {
                sql.Append(" and CALLED like '%" + Request.QueryString["CALLED"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLID"]))
            {
                sql.Append(" and CALLID = '" + Request.QueryString["CALLID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECORDCODE"]))
            {
                sql.Append(" and RECORDCODE like '%" + Request.QueryString["RECORDCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CALLTYPE"]))
            {
                sql.Append(" and CALLTYPE like '%" + Request.QueryString["CALLTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERID"]))
            {
                sql.Append(" and CUSTOMERID = '" + Request.QueryString["CUSTOMERID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERCODE"]))
            {
                sql.Append(" and CUSTOMERCODE like '%" + Request.QueryString["CUSTOMERCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CUSTOMERNAME"]))
            {
                sql.Append(" and CUSTOMERNAME like '%" + Request.QueryString["CUSTOMERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COUNTRY"]))
            {
                sql.Append(" and COUNTRY like '%" + Request.QueryString["COUNTRY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROVINCE"]))
            {
                sql.Append(" and PROVINCE like '%" + Request.QueryString["PROVINCE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PREFECTURECITY"]))
            {
                sql.Append(" and PREFECTURECITY like '%" + Request.QueryString["PREFECTURECITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CITY"]))
            {
                sql.Append(" and CITY like '%" + Request.QueryString["CITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGETOWN"]))
            {
                sql.Append(" and VILLAGETOWN like '%" + Request.QueryString["VILLAGETOWN"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VILLAGE"]))
            {
                sql.Append(" and VILLAGE like '%" + Request.QueryString["VILLAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GROUPTEAM"]))
            {
                sql.Append(" and GROUPTEAM like '%" + Request.QueryString["GROUPTEAM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ADDRESS"]))
            {
                sql.Append(" and ADDRESS like '%" + Request.QueryString["ADDRESS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FIRSTCONTACTTEL"]))
            {
                sql.Append(" and FIRSTCONTACTTEL like '%" + Request.QueryString["FIRSTCONTACTTEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BRAND"]))
            {
                sql.Append(" and BRAND like '%" + Request.QueryString["BRAND"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VEHICLETYPE"]))
            {
                sql.Append(" and VEHICLETYPE like '%" + Request.QueryString["VEHICLETYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VINCODE"]))
            {
                sql.Append(" and upper(VINCODE) like '%" + Request.QueryString["VINCODE"].ToUpper() + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTCODE"]))
            {
                sql.Append(" and PRODUCTCODE like '%" + Request.QueryString["PRODUCTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERIES"]))
            {
                sql.Append(" and SERIES like '%" + Request.QueryString["SERIES"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MODELS"]))
            {
                sql.Append(" and MODELS like '%" + Request.QueryString["MODELS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMODEL"]))
            {
                sql.Append(" and ENGINEMODEL like '%" + Request.QueryString["ENGINEMODEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ENGINEMANUFACTURERS"]))
            {
                sql.Append(" and ENGINEMANUFACTURERS like '%" + Request.QueryString["ENGINEMANUFACTURERS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILUREPARTSCODE"]))
            {
                sql.Append(" and FAILUREPARTSCODE like '%" + Request.QueryString["FAILUREPARTSCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILUREPARTS"]))
            {
                sql.Append(" and FAILUREPARTS like '%" + Request.QueryString["FAILUREPARTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAULTCODE"]))
            {
                sql.Append(" and FAULTCODE like '%" + Request.QueryString["FAULTCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SYMPTOM"]))
            {
                sql.Append(" and SYMPTOM like '%" + Request.QueryString["SYMPTOM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FULLSYMPTOM"]))
            {
                sql.Append(" and FULLSYMPTOM like '%" + Request.QueryString["FULLSYMPTOM"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILURELEVEL"]))
            {
                sql.Append(" and FAILURELEVEL like '%" + Request.QueryString["FAILURELEVEL"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SYMPTOMDESCRIPTION"]))
            {
                sql.Append(" and SYMPTOMDESCRIPTION like '%" + Request.QueryString["SYMPTOMDESCRIPTION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILUREANALYSIS"]))
            {
                sql.Append(" and FAILUREANALYSIS like '%" + Request.QueryString["FAILUREANALYSIS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATUS"]))
            {
                sql.Append(" and STATUS = '" + Request.QueryString["STATUS"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["HANDLING"]))
            {
                sql.Append(" and HANDLING like '%" + Request.QueryString["HANDLING"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["APPROACH"]))
            {
                sql.Append(" and APPROACH like '%" + Request.QueryString["APPROACH"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RESULTS"]))
            {
                sql.Append(" and RESULTS like '%" + Request.QueryString["RESULTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SEATSSUMMARY"]))
            {
                sql.Append(" and SEATSSUMMARY like '%" + Request.QueryString["SEATSSUMMARY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FAILUREOCCURS"]))
            {
                sql.Append(" and FAILUREOCCURS like '%" + Request.QueryString["FAILUREOCCURS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["GPSADDRESS"]))
            {
                sql.Append(" and GPSADDRESS like '%" + Request.QueryString["GPSADDRESS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLEID"]))
            {
                sql.Append(" and CREATEPEOPLEID = '" + Request.QueryString["CREATEPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEBegin"]))
            {
                sql.Append(" and  " + bll._dal.GetBeginDateString("CREATETIME", Request.QueryString["CREATETIMEBegin"]) + " ");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATETIMEEnd"]))
            {
                sql.Append(" and  " + bll._dal.GetEndDateString("CREATETIME", Request.QueryString["CREATETIMEEnd"]) + " ");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CREATEPEOPLE"]))
            {
                sql.Append(" and CREATEPEOPLE like '%" + Request.QueryString["CREATEPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLEID"]))
            {
                sql.Append(" and LASTMODIFYPEOPLEID = '" + Request.QueryString["LASTMODIFYPEOPLEID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYPEOPLE"]))
            {
                sql.Append(" and LASTMODIFYPEOPLE like '%" + Request.QueryString["LASTMODIFYPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYTIMEBegin"]))
            {
                sql.Append(" and  " + bll._dal.GetBeginDateString("LASTMODIFYTIME", Request.QueryString["LASTMODIFYTIMEBegin"]) + " ");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["LASTMODIFYTIMEEnd"]))
            {
                sql.Append(" and  " + bll._dal.GetEndDateString("LASTMODIFYTIME", Request.QueryString["LASTMODIFYTIMEEnd"]) + " ");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMARK"]))
            {
                sql.Append(" and REMARK like '%" + Request.QueryString["REMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DISPATCHINGTYPE"]))
            {
                sql.Append(" and DISPATCHINGTYPE like '%" + Request.QueryString["DISPATCHINGTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGOBJECTTYPE"]))
            {
                sql.Append(" and PROCESSINGOBJECTTYPE like '%" + Request.QueryString["PROCESSINGOBJECTTYPE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGDEPARTMENTID"]))
            {
                sql.Append(" and PROCESSINGDEPARTMENTID = '" + Request.QueryString["PROCESSINGDEPARTMENTID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGDEPARTMENTCODE"]))
            {
                sql.Append(" and PROCESSINGDEPARTMENTCODE like '%" + Request.QueryString["PROCESSINGDEPARTMENTCODE"] +
                           "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGDEPARTMENTNAME"]))
            {
                sql.Append(" and PROCESSINGDEPARTMENTNAME like '%" + Request.QueryString["PROCESSINGDEPARTMENTNAME"] +
                           "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGUSERID"]))
            {
                sql.Append(" and PROCESSINGUSERID = '" + Request.QueryString["PROCESSINGUSERID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGUSERNAME"]))
            {
                sql.Append(" and PROCESSINGUSERNAME like '%" + Request.QueryString["PROCESSINGUSERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGLOGINNAME"]))
            {
                sql.Append(" and PROCESSINGLOGINNAME like '%" + Request.QueryString["PROCESSINGLOGINNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DISPATCHINGTIMEBegin"]))
            {
                sql.Append(" and DISPATCHINGTIME >= '" + Request.QueryString["DISPATCHINGTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DISPATCHINGTIMEEnd"]))
            {
                sql.Append(" and DISPATCHINGTIME < '" + Request.QueryString["DISPATCHINGTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FOLLOWUPTIMEBegin"]))
            {
                sql.Append(" and FOLLOWUPTIME >= '" + Request.QueryString["FOLLOWUPTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FOLLOWUPTIMEEnd"]))
            {
                sql.Append(" and FOLLOWUPTIME < '" + Request.QueryString["FOLLOWUPTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["FOLLOWUPCONTENT"]))
            {
                sql.Append(" and FOLLOWUPCONTENT like '%" + Request.QueryString["FOLLOWUPCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGTIMEBegin"]))
            {
                sql.Append(" and PROCESSINGTIME >= '" + Request.QueryString["PROCESSINGTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGTIMEEnd"]))
            {
                sql.Append(" and PROCESSINGTIME < '" + Request.QueryString["PROCESSINGTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PROCESSINGCONTENT"]))
            {
                sql.Append(" and PROCESSINGCONTENT like '%" + Request.QueryString["PROCESSINGCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CLOSETIMEBegin"]))
            {
                sql.Append(" and CLOSETIME >= '" + Request.QueryString["CLOSETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CLOSETIMEEnd"]))
            {
                sql.Append(" and CLOSETIME < '" + Request.QueryString["CLOSETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["CLOSECONTENT"]))
            {
                sql.Append(" and CLOSECONTENT like '%" + Request.QueryString["CLOSECONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TURNTIMEBegin"]))
            {
                sql.Append(" and TURNTIME >= '" + Request.QueryString["TURNTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TURNTIMEEnd"]))
            {
                sql.Append(" and TURNTIME < '" + Request.QueryString["TURNTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TURNCONTENT"]))
            {
                sql.Append(" and TURNCONTENT like '%" + Request.QueryString["TURNCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TODOREMINDERTIMEBegin"]))
            {
                sql.Append(" and TODOREMINDERTIME >= '" + Request.QueryString["TODOREMINDERTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["TODOREMINDERTIMEEnd"]))
            {
                sql.Append(" and TODOREMINDERTIME < '" + Request.QueryString["TODOREMINDERTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REVISITINGTIMEBegin"]))
            {
                sql.Append(" and REVISITINGTIME >= '" + Request.QueryString["REVISITINGTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REVISITINGTIMEEnd"]))
            {
                sql.Append(" and REVISITINGTIME < '" + Request.QueryString["REVISITINGTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECEIVETIMEBegin"]))
            {
                sql.Append(" and RECEIVETIME >= '" + Request.QueryString["RECEIVETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECEIVETIMEEnd"]))
            {
                sql.Append(" and RECEIVETIME < '" + Request.QueryString["RECEIVETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECEIVECONTENT"]))
            {
                sql.Append(" and RECEIVECONTENT like '%" + Request.QueryString["RECEIVECONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["RECEIVEPEOPLE"]))
            {
                sql.Append(" and RECEIVEPEOPLE like '%" + Request.QueryString["RECEIVEPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEPARTURETIMEBegin"]))
            {
                sql.Append(" and DEPARTURETIME >= '" + Request.QueryString["DEPARTURETIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEPARTURETIMEEnd"]))
            {
                sql.Append(" and DEPARTURETIME < '" + Request.QueryString["DEPARTURETIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEPARTURECONTENT"]))
            {
                sql.Append(" and DEPARTURECONTENT like '%" + Request.QueryString["DEPARTURECONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEPARTUREPEOPLE"]))
            {
                sql.Append(" and DEPARTUREPEOPLE like '%" + Request.QueryString["DEPARTUREPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ARRIVALTIMEBegin"]))
            {
                sql.Append(" and ARRIVALTIME >= '" + Request.QueryString["ARRIVALTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ARRIVALTIMEEnd"]))
            {
                sql.Append(" and ARRIVALTIME < '" + Request.QueryString["ARRIVALTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ARRIVALCONTENT"]))
            {
                sql.Append(" and ARRIVALCONTENT like '%" + Request.QueryString["ARRIVALCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["ARRIVALPEOPLE"]))
            {
                sql.Append(" and ARRIVALPEOPLE like '%" + Request.QueryString["ARRIVALPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLETEDTIMEBegin"]))
            {
                sql.Append(" and COMPLETEDTIME >= '" + Request.QueryString["COMPLETEDTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLETEDTIMEEnd"]))
            {
                sql.Append(" and COMPLETEDTIME < '" + Request.QueryString["COMPLETEDTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLETEDCONTENT"]))
            {
                sql.Append(" and COMPLETEDCONTENT like '%" + Request.QueryString["COMPLETEDCONTENT"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["COMPLETEDPEOPLE"]))
            {
                sql.Append(" and COMPLETEDPEOPLE like '%" + Request.QueryString["COMPLETEDPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICENUMBER"]))
            {
                sql.Append(" and SERVICENUMBER like '%" + Request.QueryString["SERVICENUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["MILEAGE"]))
            {
                sql.Append(" and MILEAGE like '%" + Request.QueryString["MILEAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PLACEMETHOD"]))
            {
                sql.Append(" and PLACEMETHOD like '%" + Request.QueryString["PLACEMETHOD"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICEFEE"]))
            {
                sql.Append(" and SERVICEFEE like '%" + Request.QueryString["SERVICEFEE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICEHOURS"]))
            {
                sql.Append(" and SERVICEHOURS like '%" + Request.QueryString["SERVICEHOURS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REPAIRPARTS"]))
            {
                sql.Append(" and REPAIRPARTS like '%" + Request.QueryString["REPAIRPARTS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["HANDLINGINSTRUCTIONS"]))
            {
                sql.Append(" and HANDLINGINSTRUCTIONS like '%" + Request.QueryString["HANDLINGINSTRUCTIONS"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["PRODUCTSATISFACTION"]))
            {
                sql.Append(" and PRODUCTSATISFACTION like '%" + Request.QueryString["PRODUCTSATISFACTION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SERVICESATISFACTION"]))
            {
                sql.Append(" and SERVICESATISFACTION like '%" + Request.QueryString["SERVICESATISFACTION"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITTIMEBegin"]))
            {
                sql.Append(" and VISITTIME >= '" + Request.QueryString["VISITTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITTIMEEnd"]))
            {
                sql.Append(" and VISITTIME < '" + Request.QueryString["VISITTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITCOMPLETEDTIMEBegin"]))
            {
                sql.Append(" and VISITCOMPLETEDTIME >= '" + Request.QueryString["VISITCOMPLETEDTIMEBegin"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITCOMPLETEDTIMEEnd"]))
            {
                sql.Append(" and VISITCOMPLETEDTIME < '" + Request.QueryString["VISITCOMPLETEDTIMEEnd"].Trim() + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VISITREMARK"]))
            {
                sql.Append(" and VISITREMARK like '%" + Request.QueryString["VISITREMARK"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONID"]))
            {
                sql.Append(" and BUSINESSDIVISIONID = '" + Request.QueryString["BUSINESSDIVISIONID"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONNAME"]))
            {
                sql.Append(" and BUSINESSDIVISIONNAME like '%" + Request.QueryString["BUSINESSDIVISIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["BUSINESSDIVISIONCODE"]))
            {
                sql.Append(" and BUSINESSDIVISIONCODE like '%" + Request.QueryString["BUSINESSDIVISIONCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["REMINDERTIME"]))
            {
                sql.Append(" and REMINDERTIME like '%" + Request.QueryString["REMINDERTIME"] + "%'");
            }


            if (!String.IsNullOrEmpty(Request.QueryString["ENGINENUMBER"]))
            {
                sql.Append(" and ENGINENUMBER like '%" + Request.QueryString["ENGINENUMBER"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEALERCODE"]))
            {
                sql.Append(" and DEALERCODE like '%" + Request.QueryString["DEALERCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["DEALERNAME"]))
            {
                sql.Append(" and DEALERNAME like '%" + Request.QueryString["DEALERNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATIONCODE"]))
            {
                sql.Append(" and STATIONCODE like '%" + Request.QueryString["STATIONCODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["STATIONNAME"]))
            {
                sql.Append(" and STATIONNAME like '%" + Request.QueryString["STATIONNAME"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSMOBILEPHONE"]))
            {
                sql.Append(" and OWNERSMOBILEPHONE like '%" + Request.QueryString["OWNERSMOBILEPHONE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSOFFICEPHONE"]))
            {
                sql.Append(" and OWNERSOFFICEPHONE like '%" + Request.QueryString["OWNERSOFFICEPHONE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSHOMEPHONE"]))
            {
                sql.Append(" and OWNERSHOMEPHONE like '%" + Request.QueryString["OWNERSHOMEPHONE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSPEOPLE"]))
            {
                sql.Append(" and OWNERSPEOPLE like '%" + Request.QueryString["OWNERSPEOPLE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["OWNERSPEOPLECODE"]))
            {
                sql.Append(" and OWNERSPEOPLECODE like '%" + Request.QueryString["OWNERSPEOPLECODE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["SMSSTATUS"]))
            {
                sql.Append(" and SMSSTATUS = '" + Request.QueryString["SMSSTATUS"] + "'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VCOUNTRY"]))
            {
                sql.Append(" and VCOUNTRY like '%" + Request.QueryString["VCOUNTRY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VPROVINCE"]))
            {
                sql.Append(" and VPROVINCE like '%" + Request.QueryString["VPROVINCE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VPREFECTURECITY"]))
            {
                sql.Append(" and VPREFECTURECITY like '%" + Request.QueryString["VPREFECTURECITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VCITY"]))
            {
                sql.Append(" and VCITY like '%" + Request.QueryString["VCITY"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VVILLAGETOWN"]))
            {
                sql.Append(" and VVILLAGETOWN like '%" + Request.QueryString["VVILLAGETOWN"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VVILLAGE"]))
            {
                sql.Append(" and VVILLAGE like '%" + Request.QueryString["VVILLAGE"] + "%'");
            }
            if (!String.IsNullOrEmpty(Request.QueryString["VGROUPTEAM"]))
            {
                sql.Append(" and VGROUPTEAM like '%" + Request.QueryString["VGROUPTEAM"] + "%'");
            }
            #endregion

            #region 权限部分
            if (!UserLoginInfo.IsAdministrator())
            {
                //操作员当前事业务数据
                sql.Append(" and BUSINESSDIVISIONCODE = '" + _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE.Trim() + "'");

                //操作员有权看到人员的数据
                switch (UserLoginInfo.GetCurrentUserType())
                {
                    case UserType.中心部门:
                        {
                            DepartmentType departmentType = (DepartmentType)Enum.Parse(typeof(DepartmentType), _userLoginInfo.DepartmentEntity.ISCENTER.ToString());
                            if (departmentType == DepartmentType.服务部门)
                            {
                                sql.Append(String.Format(" and ProcessingObjectType = '{0}' ", _userLoginInfo.UserEntity.USERTYPE.Trim()));
                                sql.Append(String.Format(" and ProcessingDepartmentID = '{0}' ", _userLoginInfo.UserEntity.DEPARTMENTID));
                                sql.Append(caBll.GenerateContentAuthorityConditions(_userLoginInfo, "ProcessingUserID", true));

                            }
                            else
                            {
                                sql.Append(caBll.GenerateContentAuthorityConditions(_userLoginInfo, "CREATEPEOPLEID", "HELPUSERID"));
                            }
                        }
                        break;
                    case UserType.供应商:
                    case UserType.市场部:
                    case UserType.服务商:
                    case UserType.经销商:
                        {
                            sql.Append(String.Format(" and ProcessingObjectType = '{0}' ", _userLoginInfo.UserEntity.USERTYPE.Trim()));
                            sql.Append(String.Format(" and ProcessingDepartmentID = '{0}' ", _userLoginInfo.UserEntity.DEPARTMENTID));
                            //sql.Append(caBll.GenerateContentAuthorityConditions(_userLoginInfo, "ProcessingUserID", true));
                        }
                        break;
                }
                

                //操作员角色需待办数据
                sql.Append(roleOrderStatusAuthorityBll.GenerateStatusAuthorityConditions(_userLoginInfo,
                                                                                         WorkOrderType.报修工单, "STATUS"));


            }
            #endregion

            return sql;

        }

        /// <summary>
        /// 页面数据绑定
        /// </summary>
        private void gvDataBinding()
        {
            #region 查询条件字符串

            StringBuilder sql = GenerationSQLString();

            #endregion

            List<T_REPAIRCASE_Entity> list;

            //获取总的记录条数
            gvList.RecordCount = (int) bll.GetCount(sql.ToString());

            list = bll.GetList(sql.ToString(), gvList.CurrentPageIndex*gvList.PageSize, gvList.PageSize,
                               gvList.SortConditions);

            gvList.DataSource = list;
            gvList.DataKeyNames = new string[] { "CASEID", "ToDoReminderTime", "STATUS", "PROCESSINGCOMPLETEDTIME" };
            gvList.DataBind();

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string url = HttpContext.Current.Request.Url.AbsolutePath;
            PageHelper.GetControlToUrlQuery(this.Page, ref url);
            Response.Redirect(url);
        }

        #region GridView 事件

        /// <summary>
        /// GridView 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            T_REPAIRCASE_Entity entity = new T_REPAIRCASE_Entity();
            entity.CASEID = StringHelper.ToLong((sender as GridView).DataKeys[e.RowIndex].Values[0].ToString());

            long rel = bll.Delete(entity);
            if (rel > 0)
            {
                Response.Redirect(HttpContext.Current.Request.RawUrl);
            }
            else
            {

            }

        }

        /// <summary>
        /// GridView 行数据绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string temp = string.Empty;
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {
                        GridView gv = (sender as GridView);
                        for (int i = 0; i < gv.Columns.Count; i++)
                        {
                            TemplateField tf = gv.Columns[i] as TemplateField;
                            if (tf != null)
                            {
                                #region 存储值 转换成  显示值

                                switch (tf.HeaderText)
                                {
                                    case "操作":
                                        {
                                            e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
                                        }
                                        break;
                                    default:
                                        {
                                            e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
                                        }
                                        break;

                                }

                                #endregion
                            }

                            BoundField bf = gv.Columns[i] as BoundField;
                            if (bf != null)
                            {
                                #region 存储值 转换成  显示值

                                switch (bf.DataField)
                                {
                                    case "PROCESSINGOBJECTTYPE":
                                        {
                                            try
                                            {
                                                temp = e.Row.Cells[i].Text.Trim();
                                                temp =
                                                    ((UserType)Enum.Parse(typeof(UserType), temp)).ToString();
                                                e.Row.Cells[i].Text = temp;
                                            }
                                            catch (Exception ex)
                                            {
                                                
                                            }
                                        }
                                        break;
                                    case "DISPATCHINGTYPE":
                                        {
                                            try
                                            {
                                                temp = e.Row.Cells[i].Text.Trim();
                                                temp =
                                                    ((DispatchingType)Enum.Parse(typeof(DispatchingType), temp)).ToString();
                                                e.Row.Cells[i].Text = temp;
                                            }
                                            catch (Exception ex)
                                            {
                                                
                                            }
                                        }
                                        break;
                                    case "STATUS":
                                        {
                                            try
                                            {
                                                temp = e.Row.Cells[i].Text.Trim();
                                                T_WORKORDERSTATUS_Entity entity =
                                                    workOrderStatusBll.GetPageItem_T_WORKORDERSTATUS_EntityByKey(this.Page, StringHelper.ToInt(temp, 0));
                                                if (entity != null)
                                                {
                                                    temp = entity.ORDERSTATUSNAME;
                                                    if (!String.IsNullOrEmpty(entity.RECORDSTYLE))
                                                    {
                                                        e.Row.Attributes["style"] = entity.RECORDSTYLE;

                                                    }
                                                }
                                                e.Row.Cells[i].Text = temp;
                                            }
                                            catch (Exception ex)
                                            {
                                                
                                            }
                                        }
                                        break;
                                    default:
                                        {

                                        }
                                        break;
                                }

                                #endregion
                            }
                        }

                        #region 超期样式
                        DateTime dt = DateTime.Now;
                        temp = (gv.DataKeys[e.Row.RowIndex].Values["ToDoReminderTime"] == null) ? "" : gv.DataKeys[e.Row.RowIndex].Values["ToDoReminderTime"].ToString();
                        string status = (gv.DataKeys[e.Row.RowIndex].Values["STATUS"] == null) ? "" : gv.DataKeys[e.Row.RowIndex].Values["STATUS"].ToString();
                        if (DateTime.TryParse(temp, out dt))
                        {
                            if (dt.CompareTo(DateTime.Now) < 0)
                            {
                                try
                                {
                                    if (workOrderStatusBll.GetSessionStatusType(this.Page, status) == StatusType.中间节点)
                                    {
                                        e.Row.Attributes["style"] = configBll.GetCacheValueByName(this.Page, "ExtendedStyle");
                                    }
                                }
                                catch (Exception)
                                {

                                }
                            }
                        }
                        temp = (gv.DataKeys[e.Row.RowIndex].Values["PROCESSINGCOMPLETEDTIME"] == null) ? "" : gv.DataKeys[e.Row.RowIndex].Values["PROCESSINGCOMPLETEDTIME"].ToString();
                        if (DateTime.TryParse(temp, out dt))
                        {
                            if (dt.AddHours(4).CompareTo(DateTime.Now) < 0)
                            {
                                try
                                {
                                    if (workOrderStatusBll.GetSessionStatusType(this.Page, status) == StatusType.回访节点)
                                    {
                                        e.Row.Attributes["style"] = configBll.GetCacheValueByName(this.Page, "ExtendedStyle");
                                    }
                                }
                                catch (Exception)
                                {

                                }
                            }
                        }
                        #endregion
                    }
                    break;
                case DataControlRowType.Header:
                    {

                    }
                    break;
                case DataControlRowType.Pager:
                    {

                    }
                    break;
                case DataControlRowType.EmptyDataRow:
                    {


                    }
                    break;
                default:

                    break;
            }

        }

        /// <summary>
        /// GridView 行创建事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvList_RowCreated(object sender, GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {

                    }
                    break;
                case DataControlRowType.Header:
                    {

                    }
                    break;
                case DataControlRowType.Pager:
                    {

                    }
                    break;
                case DataControlRowType.EmptyDataRow:
                    {


                    }
                    break;
                default:

                    break;
            }

        }

        #endregion

    }
}
